﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Collections;
using System.Linq.Expressions;

namespace ASPItalia.ModelVirtualCasting.EntityFramework.Wrappers {
	internal class ObjectSetWrapper<T> : IIncludeObjectSet<T> where T : class {
		private ObjectSet<T> objectSet;
		private ObjectQuery<T> objectQuery;

		public ObjectSetWrapper(ObjectSet<T> objectSet) {
			this.objectSet = objectSet;
			this.objectQuery = objectSet;
		}

		public void AddObject(T entity) {
			this.objectSet.AddObject(entity);
		}

		public void Attach(T entity) {
			this.objectSet.Attach(entity);
		}

		public void DeleteObject(T entity) {
			this.objectSet.DeleteObject(entity);
		}

		public void Detach(T entity) {
			this.objectSet.Detach(entity);
		}

		#region IEnumerable<T> Members

		public IEnumerator<T> GetEnumerator() {
			return ((IEnumerable<T>)this.objectSet).GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator() {
			return ((IEnumerable)this.objectSet).GetEnumerator();
		}

		#endregion

		#region IQueryable Members

		public Type ElementType {
			get { return ((IQueryable)this.objectQuery).ElementType; }
		}

		public Expression Expression {
			get { return ((IQueryable)this.objectQuery).Expression; }
		}

		public IQueryProvider Provider {
			get { return ((IQueryable)this.objectQuery).Provider; }
		}

		#endregion

		#region IObjectQuery<T> Members

		public IObjectQuery<T> Include(string path) {
			objectQuery = objectQuery.Include(path);
			return this;
		}

		#endregion
	}
}